﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ServiceStack;
using EquipmentManager.Properties;

namespace EquipmentManager.OALogin
{
    public class OaLoginHelper
    {
        static JsvServiceClient client = new JsvServiceClient(Settings.Default.OAServerAddr);
        static public OaUser login(string username, string password)
        {
            try
            {
                Password ps = new Password { PassWord = password, UserId = username, Time = DateTime.Now };
                string tmp = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(ps.ToJsv()));
                OaUser user = client.Get<OaUser>(new GetUserInfo { pass = tmp });
                return user;
            }
            catch (Exception)
            {
                return null;
            }
        }
    }
    public class OaUser
    {
        public int uid { get; set; }
        public string user_id { get; set; }
        public string user_name { get; set; }
        public string password { get; set; }
        public string department { get; set; }
        public string position { get; set; }


        public override string ToString()
        {
            return String.Format("id={0},登录名={1},名字={2},密码={3},部门={4},职位={5}",
            uid, user_id, user_name, password, department, position);
        }
    }
    class Password
    {
        public DateTime Time { get; set; }
        public string UserId { get; set; }
        public string PassWord { get; set; }
    }
    class GetUserInfo
    {
        public string pass { get; set; }
    }
}
